//--- Projeto Domus
// interactionsource.com
// Koji Pereira, Andre Veloso e Marcos Paulo

/*
 Projeto Domus
 interactionsource.com
 Koji Pereira, Andre Veloso e Marcos Paulo

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


package com.interactionsource.input.wiimoteosc;
/*
 * 
 */

import java.io.IOException;
import java.net.SocketException;

import org.wiigee.device.Device;
import org.wiigee.util.Log;

import com.illposed.osc.OSCPortIn;


/**
 * 
 * 
 *
 * @author 
 */
public class WiimoteOSC extends Device {
	
	private int OSCPort;
	private OSCPortIn receiver;
	
	
    public WiimoteOSC(String btaddress, boolean autofiltering, boolean autoconnect) throws IOException {
        super(autofiltering);
	
    }
    
    public WiimoteOSC(int connectionPort, boolean autofiltering) throws IOException {
        super(autofiltering);      
            
        
        OSCPort = connectionPort;              		
		
		try {
			receiver = new OSCPortIn(OSCPort);

			Log.write("WiimoteOSC - WiimoteOSC initialized... Recebendo dados via OSC na porta: " + connectionPort);

		} catch (SocketException e) {

			e.printStackTrace();
			Log.write("WiimoteOSC - Erro ao abrir porta OSC " + this.OSCPort);
		}
        
	
    }   
    
    public void mostraSaida() {
    	
	
    }
    
    public OSCPortIn getReceiveConnection() {
        return this.receiver;
    }

	/**
	 * @return the oSCPort
	 */
	public int getOSCPort() {
		return OSCPort;
	}

	/**
	 * @param oSCPort the oSCPort to set
	 */
	public void setOSCPort(int oSCPort) {
		this.OSCPort = oSCPort;
		
		//Fecha a porta antiga e abre com a nova porta
		this.receiver.stopListening();
		this.receiver.close();
		// TODO - Implementar re-inicializacao do dispositivo
		/*
		try {
			this.receiver = new OSCPortIn(this.OSCPort);
			
			this.receiver.startListening();
			
			Log.write("WiimoteOSC - WiimoteOSC re-initialized... Recebendo dados via OSC na NOVA porta: " + this.OSCPort);
		} catch (SocketException e) {
			e.printStackTrace();
			Log.write("WiimoteOSC - Erro ao abrir porta OSC " + this.OSCPort);
		}
		*/
	}    
    
   
    
}
    
